#!/bin/bash
#
# Input: proc name (as aino.lib target basename), e.g. P16F873
# Output: proc speed (FOSC), e.g. 4000000
#
# Adapt clock speed (FOSC) in 'xtal.sh'
#
wd=$(dirname $0)
MHz=1000000

case $(${wd}/xtal.sh $1 ) in
 3)
  echo "3.57945 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 4)
  echo "4.0 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 5)
  echo "5.0688 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 7)
  echo "7.15909 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 10)
  echo "10.0 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 12)
  echo "12.0 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 16)
  echo "16.0 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 20)
  echo "20.0 * ${MHz}" | bc -l | sed 's/\..*//' ;;
 *)
  cat<<EOF>&2
Undefined XTAL for $1
EOF
  exit 1 ;;
esac
